package com.github.barry.controller

import com.github.barry.entity.User
import com.github.barry.service.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{PathVariable, PostMapping, RequestMapping, RestController}

/**
 * @ClassName UserController
 * @Description TODO
 * @Author wangxuexing
 * @Date 2020/3/17 10:56
 * @Version 1.0
 */
@RestController
@RequestMapping(value = Array("user"))
class UserController @Autowired()(val userService: UserService) {
  @PostMapping(value = Array("save/{name}"))
  def save(@PathVariable name: String): Long = {
    val userModel = {
      new User
    }
    userModel.name = name
    this.userService.save(userModel).id
  }

  @PostMapping(value = Array("findAll"))
  def findAll(): java.lang.Iterable[User] = {
    userService.findAll()
  }
}
